package com.ruoyi.bulkegg.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bulkegg.domain.SupplyRelationCompany;
import com.ruoyi.bulkegg.service.ISupplyRelationCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商关系Controller
 * 
 * @author ruoyi
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/bulkegg/company")
public class SupplyRelationCompanyController extends BaseController
{
    @Autowired
    private ISupplyRelationCompanyService supplyRelationCompanyService;

    /**
     * 查询供应商关系列表
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplyRelationCompany supplyRelationCompany)
    {
        startPage();
        List<SupplyRelationCompany> list = supplyRelationCompanyService.selectSupplyRelationCompanyList(supplyRelationCompany);
        return getDataTable(list);
    }

    /**
     * 导出供应商关系列表
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:export')")
    @Log(title = "供应商关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplyRelationCompany supplyRelationCompany)
    {
        List<SupplyRelationCompany> list = supplyRelationCompanyService.selectSupplyRelationCompanyList(supplyRelationCompany);
        ExcelUtil<SupplyRelationCompany> util = new ExcelUtil<SupplyRelationCompany>(SupplyRelationCompany.class);
        util.exportExcel(response, list, "供应商关系数据");
    }

    /**
     * 获取供应商关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(supplyRelationCompanyService.selectSupplyRelationCompanyByCompanyId(companyId));
    }

    /**
     * 新增供应商关系
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:add')")
    @Log(title = "供应商关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplyRelationCompany supplyRelationCompany)
    {
        return toAjax(supplyRelationCompanyService.insertSupplyRelationCompany(supplyRelationCompany));
    }

    /**
     * 修改供应商关系
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:edit')")
    @Log(title = "供应商关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplyRelationCompany supplyRelationCompany)
    {
        return toAjax(supplyRelationCompanyService.updateSupplyRelationCompany(supplyRelationCompany));
    }

    /**
     * 删除供应商关系
     */
    @PreAuthorize("@ss.hasPermi('bulkegg:company:remove')")
    @Log(title = "供应商关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(supplyRelationCompanyService.deleteSupplyRelationCompanyByCompanyIds(companyIds));
    }
}
